package com.oopnet.template.test.patterns;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public class Teacher implements Observer{
	
	
	@Override
	public void update(Observable o, Object arg) {
		System.out.println(o+" Say something: "+ arg);
	}
	
	public void addStudent(Observable o ){
		o.addObserver(this);
	}
	
	@Transactional(
			isolation=Isolation.READ_COMMITTED,
			propagation=Propagation.MANDATORY,
			timeout=3000,
			readOnly=false)
	public void addStudents(List<Student> list ){
		for (Observable observable : list) {
			observable.addObserver(this);
		}
	}
	
	public static void main(String[] args) {
		Student s1 = new Student("Yang");
		Student s2 = new Student("Zhang");
		Student s3 = new Student("Li");
		Student s4 = new Student("Wang");
		
		Teacher t = new Teacher();
		List<Student> listStu = new ArrayList<Student>();
		listStu.add(s1);
		listStu.add(s2);
		listStu.add(s3);
		listStu.add(s4);
		t.addStudents(listStu);
//		s1.addObserver(t);
		s1.saySomeThing("Hello Mary");
		s4.saySomeThing("Play basketball after class!");
		
	}
}
